import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;



public class Server{
	
	
	
	public static void main(String[] args) throws IOException, ClassNotFoundException {
		String host = "127.0.0.1"; int port = 6000;
		
		ObjectOutputStream os = null;
		Socket server = null;
		ServerSocket s = new ServerSocket(6000);
		ObjectInputStream is = null;
		
		DataInputStream dis = null;
		try {
			server = s.accept();
			System.out.println("CONNECTED");
			is = new ObjectInputStream(server.getInputStream());
			os = new ObjectOutputStream(server.getOutputStream());	
			
			while(true){
			
			String msg = (String)is.readObject();
			System.out.println(msg);
			
			if (msg.length() ==0){
				System.out.println("Close socket : " + server.getInetAddress());
				is.close();
				os.close();
			}
			}
		
		} catch (IOException e) {
			e.printStackTrace();
		}
		is.close();
		os.close();
		}
	
	}
	
	
	
	
	